package p100;

import java.util.Stack;

public class Leetcode_162 {
    public int findPeakElement(int[] nums) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < nums.length; i++) {
            if (stack.empty() || stack.peek() < nums[i]) {
                stack.push(nums[i]);
            } else {
                return i - 1;
            }
        }
        return nums.length - 1;
    }

    public static void main(String[] args) {
        System.out.println(new Leetcode_162().findPeakElement(new int[]{1, 2, 3, 1}));
    }
}
